import React from 'react'
import {useLocation} from "react-router-dom"
import { SubmitBar } from 'react-vant';
import {useDispatch,useSelector} from "react-redux"
import * as atcion from "../action"
function Detail() {
   const loaction = useLocation()
   const dispatch = useDispatch()
   console.log(loaction);
   const {item} = loaction.state
   const addshopcar = (item)=>{
       // 1.在组件中调用action里的方法
       //2 . 去 action中写这个方法
       // 3. reducer
       dispatch(atcion.addshop(item))
        console.log(item);
   }
  return (
    <div>
        <img src={item.img} alt=""  style={{width:"100%",height:"auto"}}/>
        <h4>商品名：{item.title}</h4>
        <SubmitBar price={item.price * 100} buttonText="加入购物车"  onSubmit = {()=>addshopcar(item)}/>
    </div>
  )
}

export default Detail